#ifndef ACONNECTION_H
#define ACONNECTION_H

#include <QObject>
#include <stdint.h>
#include <QTcpSocket>
#include <QHostAddress>

typedef void(*ConnCallback)();


class AConnection :QObject
{
    Q_OBJECT
public:
    AConnection(ConnCallback successCb = NULL, ConnCallback errorCb = NULL,QObject* parent  = 0);


    void setHostAddress(QHostAddress& addr);
    void setPort(int port);

    void close();

public slots:
    void startConnect();
    void startConnect(QHostAddress& addr, int port);

private slots:
    void onConnected();
    void onError(QAbstractSocket::SocketError);

private:
    QHostAddress mIpAddress;
    int        mPort;
    int        mDomain;
    int        mSubdomain;

    QTcpSocket mSocket;

    ConnCallback   mErrorCb;
    ConnCallback   mSuccessCb;
};

#endif // ACONNECTION_H
